//导入multer
const multer = require("multer");
const path = require("path");
const {filePath} = require("../config");
const {v4: uuidv4} = require('uuid');
// 设置存储配置
const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, path.join(path.resolve(__dirname), '../', filePath)) // 确保这个文件夹已经存在
    },
    filename: function (req, file, cb) {
        // 解决中文名乱码的问题
        file.originalname = Buffer.from(file.originalname, "latin1").toString(
            "utf8"
        );
        let extname = path.extname(file.originalname);
        cb(null, uuidv4() + extname)
    }
})

const upload = multer({storage: storage});

module.exports = {
    upload
}
